<?php if (!defined('SERVER_ROOT')) {exit('No direct script access allowed');}
//header
$this->template->title = 'Hồ sơ';
$this->template->display('dsp_header.php');

$MA_THU_TUC = 0;
$TEN_THU_TUC = '';
$MA_DON_VI_TIEP_NHAN= '';
$TEN_DON_VI_TIEP_NHAN = '';
$MA_HO_SO = 0;
$SO_HO_SO='';
$SO_BIEN_NHAN='';
$VE_VIEC='';
$HO_SO_GOM_CO='';
$GHI_CHU='';
$MA_QTTT=0;
$TGQD_HO_SO=0;
$MUC_LE_PHI=0;
$NGAY_NHAN_HO_SO='';
$NGAY_HEN_TRA_KET_QUA='';
$NGAY_THONG_BAO_NOP_CKT='';
$NGAY_NOP_BIEN_LAI_DONG_CKT='';
$NGAY_LANH_DAO_KY_QUYET='';
$NGAY_TRA_KET_QUA='';
$CMND_CONG_DAN_NOP='';
$TEN_CONG_DAN_NOP='';
$DIA_CHI_CONG_DAN_NOP='';
$DI_DONG_LIEN_LAC_CONG_DAN='';
$MA_TO_TIEP_NHAN=0;
$MA_CAN_BO_TIEP_NHAN=0;
$XML_BIEU_MAU='';
$XML_HO_SO_GOM_CO='';
$SO_LAN_IN_PTN='';
while ($arr = $arr_single_hoso->FetchRow()){
    $MA_THU_TUC = $arr['MA_THU_TUC'];
    $TEN_THU_TUC = $arr['TEN_THU_TUC'];
    $MA_DON_VI_TIEP_NHAN= $arr['MA_DON_VI_TIEP_NHAN'];
    $TEN_DON_VI_TIEP_NHAN = $arr['TEN_DON_VI_TIEP_NHAN'];
    $MA_HO_SO = $arr['MA_HO_SO'];
    $SO_HO_SO=$arr['SO_HO_SO'];
    $SO_BIEN_NHAN=$arr['SO_BIEN_NHAN'];
    $VE_VIEC=$arr['VE_VIEC'];
    $HO_SO_GOM_CO=$arr['HO_SO_GOM_CO'];
    $GHI_CHU=$arr['GHI_CHU'];
    $MA_QTTT=$arr['MA_QTTT'];
    $TGQD_HO_SO=$arr['TGQD_HO_SO'];
    $MUC_LE_PHI=$arr['MUC_LE_PHI'];
    $NGAY_GIO_TIEP_NHAN=$arr['NGAY_GIO_TIEP_NHAN'];
    $NGAY_GIO_HEN_TRA=$arr['NGAY_GIO_HEN_TRA'];
    $NGAY_GIO_TB_NOP_CKT=$arr['NGAY_GIO_TB_NOP_CKT'];
    $NGAY_GIO_NOP_BL_DONG_CKT=$arr['NGAY_GIO_NOP_BL_DONG_CKT'];
    $NGAY_GIO_KY_DUYET=$arr['NGAY_GIO_KY_DUYET'];
    $NGAY_GIO_TRA_KET_QUA=$arr['NGAY_GIO_TRA_KET_QUA'];
    $CMND_CONG_DAN_NOP=$arr['CMND_CONG_DAN_NOP'];
    $TEN_CONG_DAN_NOP=$arr['TEN_CONG_DAN_NOP'];
    $DIA_CHI_CONG_DAN_NOP=$arr['DIA_CHI_CONG_DAN_NOP'];
    $DI_DONG_LIEN_LAC_CONG_DAN=$arr['DI_DONG_LIEN_LAC_CONG_DAN'];
    $MA_TO_TIEP_NHAN=$arr['MA_TO_TIEP_NHAN'];
    $MA_CAN_BO_TIEP_NHAN=$arr['MA_CAN_BO_TIEP_NHAN'];
    $XML_BIEU_MAU=$arr['XML_BIEU_MAU'];
    $XML_HO_SO_GOM_CO=$arr['XML_HO_SO_GOM_CO'];
    $SO_LAN_IN_PTN=$arr['SO_LAN_IN_PTN'];
}

$xml_file_path = $this->get_xml_config($MA_THU_TUC, 'form_struct');

if (is_file($xml_file_path)){
    $v_xml_string = file_get_contents($xml_file_path);
}else{
    $v_xml_string = '';
}

?>
 <form name="frmMain" id="frmMain" action="" method="POST"
	enctype="multipart/form-data">
     <?php
        echo $this->hidden('controller', $this->get_controller_url());
        echo $this->hidden('XmlData',$XML_BIEU_MAU);
        echo $this->hidden('hdn_item_id', $MA_HO_SO);
        echo $this->hidden('hdn_deleted_file_id_list', '');
    ?>
    <h3 style="text-align: center"><?php echo $SO_HO_SO; ?></h3>
    <div style="font-style: italic"><?php echo $TEN_THU_TUC; ?>  </div>
    <!-- *********THÔNG TIN CHUNG************* -->
    <div id="div_thongtinnguoinop"  class="panel_color">Thông tin chung</div>
	<table id="tbl_thongtinnguoinop"
           class="none-border-table"
           style="width: 100%;">
		<tbody>
        <tr>
			<td width="20%">Tiếp nhận của ông/bà:<span class="text_color_red">(*)</span></td>
			<td colspan="3">

            CMND:<span class="text_color_red">(*)</span>
            <input type="text" data-doc="no" data-xml="no"
                   data-name="CMND" data-validate="text"
                   data-allownull="no" value="<?php echo $CMND_CONG_DAN_NOP; ?>"
                   style="width: 80px"
                   maxlength="9" id="txt_CMND_CONG_DAN" name="txt_CMND_CONG_DAN">
             Họ và tên:<span class="text_color_red">(*)</span>
             <input type="text" data-doc="no"
                   data-xml="no" data-name="họ và tên"
                   data-validate="text" data-allownull="no"
                   value="<?php echo $TEN_CONG_DAN_NOP; ?>"
                   readonly="readonly" style="width: 200px"
                   maxlength="50" id="txt_TEN_CONG_DAN" name="txt_TEN_CONG_DAN">
             Di động liên lạc:
             <input type="text" data-doc="no"
                   data-xml="no" data-name="họ và tên"
                   data-validate="text" value="<?php echo $DI_DONG_LIEN_LAC_CONG_DAN; ?>"
                   readonly="readonly" style="width: 150px" maxlength="50"
                   id="txt_DI_DONG_LIEN_LAC_CONG_DAN"
                   name="txt_DI_DONG_LIEN_LAC_CONG_DAN">
            </td>


        </tr>
        <tr>
			<td width="20%">Địa chỉ:</td>
			<td colspan="3">
            <input type="text" data-doc="no" data-xml="no"
                   data-name="về việc" data-validate="text"
                   readonly="readonly"
                   value="<?php echo $DIA_CHI_CONG_DAN_NOP; ?>"
                   style="width: 99%" maxlength="300"
                   id="txt_DIA_CHI" name="txt_DIA_CHI">
           </td>
        </tr>
        <tr>
			<td width="20%">Về việc:<span class="text_color_red">(*)</span></td>
			<td colspan="3">
            <input type="text" data-doc="no" data-xml="no"
                   data-name="về việc" data-validate="text"
                   data-allownull="no"
                   value="<?php echo $VE_VIEC; ?>"
                   style="width: 99%" maxlength="300"
                   id="txt_VE_VIEC" name="txt_VE_VIEC">
           </td>
        </tr>
        <tr>
			<td width="20%">Ghi chú:</td>
			<td colspan="3">
            <input type="text" data-doc="no" data-xml="no"
                   data-name="hồ sơ gồm có" data-validate="text"
                   value="<?php  echo $GHI_CHU; ?>"
                   style="width: 99%" maxlength="250"
                   id="txt_GHI_CHU" name="txt_GHI_CHU">
           </td>
        </tr>
        <tr>
        <td width="20%">Thời gian giải quyết:</td>
			<td colspan="3">
            <input type="text" data-doc="no" data-xml="no"
                   data-name="CMND" data-validate="text"
                   data-allownull="no" value="<?php echo $TGQD_HO_SO; ?> ngày"
                   style="width: 50px"  readonly="readonly"
                   maxlength="9" id="txt_TGQD_HO_SO" name="txt_TGQD_HO_SO">
            Ngày giờ tiếp nhận:
            <input type="text" data-doc="no" data-xml="no"
                   data-name="CMND" data-validate="text"
                   data-allownull="no" value="<?php echo $NGAY_GIO_TIEP_NHAN; ?>"
                   style="width: 150px"  readonly="readonly"
                   maxlength="9" id="txt_NGAY_GIO_TIEP_NHAN" name="txt_NGAY_GIO_TIEP_NHAN">
             Ngày giờ hẹn trả:
             <input type="text" data-doc="no"
                   data-xml="no" data-name="họ và tên"
                   data-validate="text" data-allownull="no"
                   value="<?php echo $NGAY_GIO_HEN_TRA; ?>"
                   readonly="readonly" style="width: 150px"
                   maxlength="50" id="txt_NGAY_GIO_HEN_TRA" name="txt_NGAY_GIO_HEN_TRA">
            </td>
        </tr>
        <tr>
			<td>File đính kèm:</td>
			<td colspan="3">
            <input type="file"
				style="border: solid #D5D5D5; color: #000000"
				class="multi accept-<?php echo _CONST_RECORD_FILE_ACCEPT;?>"
				name="uploader[]" id="File1" />
                <font style="font-weight: normal;font-size: smaller">
                Hệ thống chỉ chấp nhận đuôi file dạng:</font>
                <span style="font-weight: normal;font-size: smaller"
				class="fileUploaderMessage"> doc; docx; pdf;</span><br />
                <?php while ($arr = $arr_all_filehoso->FetchRow()): ?>
                        <?php
                            $v_file_id      = $arr['MA_FILE_HO_SO'];
            		        $v_file_name    = $arr['TEN_FILE_HO_SO'];
            		        $v_file_path    = SITE_ROOT . 'uploads/hoso/' . $v_file_name;
            		        echo '<span id="file_' . $v_file_id . '">';
            		        echo '<img src="' . SITE_ROOT . 'public/images/trash.png" style="cursor:pointer" onclick="delete_file(' . $v_file_id . ')">&nbsp;';
            		        echo '<a href="' . $v_file_path .'" target="_blank">' .$v_file_name . '</a><br/>';
            		        echo '</span>';
                        ?>

                <?php endwhile; ?>
            </td>
		</tr>

	</tbody>
</table>
<!-- ************ Thành phần hồ sơ-->

    <div id="div_giayto"  class="panel_color"> Thành phần hồ sơ


    </div>
    <div id="div_chk">
        <table border="0" style="width:100%; border-style: none;" cellpadding="0" cellspacing="0">

            <?php
            $TEN_GIAY_TO = '';
            $SO_BAN = 0;
            $LOAI = 0;
            $MA_GIAY_TO = 0;
            $arrhs = explode(",", $XML_HO_SO_GOM_CO);
            $i = 0;

            while ($arr = $arr_all_giayto->FetchRow()) {
                $TEN_GIAY_TO = $arr['TEN_GIAY_TO'];
                $SO_BAN = $arr['SO_BAN'];
                $LOAI = $arr['LOAI'];
                $MA_GIAY_TO = $arr['MA_GIAY_TO'];
                $TEN_LOAI = '';

                if ($LOAI == 1) {
                    $TEN_LOAI = 'bản sao';
                } else if ($LOAI == 2) {
                    $TEN_LOAI = 'bản chính';
                } else if ($LOAI == 3) {
                    $TEN_LOAI = 'bản chính hoặc bản sao';
                } else if ($LOAI == 4) {
                    $TEN_LOAI = 'bản viết tay';
                } else if ($LOAI == 0) {
                    $TEN_LOAI = 'bản';
                }
                $chuoi = $TEN_GIAY_TO . " (" . $SO_BAN . " " . $TEN_LOAI . ")";
                ?>
                <tr><td width="20%" style="border:none;">&nbsp;</td>
                    <td style="border:none;">
                        <?php
                        $checked = '';
                        for ($i = 0; $i < count($arrhs); $i++) {
                            if ($arrhs[$i] == $chuoi) {
                                $checked = 'checked="checked"';
                            }
                        }
                        ?>
                        <input type="checkbox" name="chk_tphs[]" <?php echo $checked; ?> value="<?php echo $chuoi; ?>">  <?php echo $chuoi; ?>
                    </td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <!-- ************ END thành phần hồ so -->
<!-- *********PHẦN BIỂU MẪU NẰM TRONG record_detail************* -->
<div id="record_detail">
   <div id="xml_part"> <?php echo $this->transform($xml_file_path); ?> </div>
</div>
<!-- *********BUTTON CẬP NHẬT************* -->
</form>

<script>
    $(document).ready(function() {
        var formHelper = new DynamicFormHelper('','',document.frmMain);
        formHelper.BindXmlData();
    });
</script>
<?php $this->template->display('dsp_footer.php');